/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package aptech.semester.code.gui;

import aptech.semester.code.common.Constants;
import aptech.semester.code.conn.MyLib;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import sun.nio.ch.FileKey;


/**
 *
 * @author vi
 */
public class HRMS {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
         for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
               javax.swing.UIManager.setLookAndFeel(info.getClassName());
               break;
            }
         }
      } catch (ClassNotFoundException ex) {
         java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
         java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
         java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (javax.swing.UnsupportedLookAndFeelException ex) {
         java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      }
        File f = null;
        try {
            f = new File(Constants.PATH_FOLDER_CONFIG);
            if (!f.exists()) {
                FileUtils.forceMkdir(f);
                File file = new File(Constants.PATH_FOLDER_CONFIG + Constants.NAME_FILE_CONFIG);
                boolean createFile = file.createNewFile();
                if (createFile) {
                    InputStream in  = HRMS.class.getClassLoader().getResourceAsStream(Constants.FILE_CONFIG);
                    // copy file from aptech/semester/code/conn/config.properties to folder has created
                    FileUtils.copyInputStreamToFile(in, file);
                }
            }
            
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        
        Connection cnn = MyLib.getCN();
        MainScreen main = new MainScreen();
//        main.setVisible(false);
        main.setVisible(true);
        if (cnn == null) {
            main.addNewInternalFrame(new ConnectDatabase(main));
            
            
        } else {
            
            main.addNewInternalFrame(new Login(main));
        }
        
        
    }
    
}
